<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui,chosen'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
        .has-no{color:#3366cc;}
        .has-success{color: #1ab394;}
        .has-warning{color: #f8ac59;}
        .has-error{color: #ed5565;}
        .has-receive{color: #9E792E;}
        .remark {
            width: 100%; /*自动适应父布局宽度*/
            overflow: auto;
            word-break: break-all;
        }
    </style>
    <%}%>
</head>

<body>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins" style="margin-bottom: 0px;">
                <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                    <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                        <div class="form-group">
                            <label class="control-label col-sm-1">主体:</label>
                            <div class="col-sm-2">
                                <select  name="shopName" class="form-control">
                                    <option value="">全部</option>
                                    <%for(var dict in shop){%>
                                    <option value="${dict.detailName}">${dict.detailName}</option>
                                    <%}%>
                                </select>
                            </div>
                            <label class="control-label col-sm-1">店铺:</label>
                            <div class="col-sm-2">
                                <select  name="brandName" class="form-control">
                                    <option value="">全部</option>
                                    <%for(var dict in brand){%>
                                    <option value="${dict.detailName}">${dict.detailName}</option>
                                    <%}%>
                                </select>
                            </div>
                            <label class="control-label col-sm-1">国家:</label>
                            <div class="col-sm-2">
                                <select name="countryName" class="form-control">
                                    <option value="">全部</option>
                                    <%for(var dict in country){%>
                                    <option value="${dict.detailName}">${dict.detailName}</option>
                                    <%}%>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-sm-1">状态:</label>
                            <div class="col-sm-2">
                                <select id="flag" name="flag" class="form-control">
                                    <option value="">全部分类</option>
                                    <option value="0" >未处理</option>
                                    <option value="1" >处理中</option>
                                    <option value="2" >处理失败</option>
                                    <option value="3" >处理成功</option>
                                </select>
                            </div>
                            <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                        </div>
                    </form>
                </div>

            </div>


            <div id="toolbar" class="btn-group" style="margin-bottom:5px;">
                <button  class="import-v2-btn layui-btn layui-btn-sm import-btn" style="margin-left: -2px"    >
                    <i class="layui-icon"></i>导入V2数据
                </button>

                <button  class="deal-v2-btn layui-btn layui-btn-sm deal-btn" style="margin-left: -2px"    >
                    <i class="layui-icon"></i>处理V2数据
                </button>

                <button  class="reload-btn layui-btn  layui-btn-sm btn-info"  style="">
                    <i class="fa fa-check-square-o" aria-hidden="true"></i> 清空V2数据
                </button>
            </div>
            <!-- START 数据表格 -->
            <table id="portTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-url="/sea/finance/vtFile/findByCnd.do"
                   data-page-size="15"
                   class="table table-striped table-hover"
            >
            </table>
        </div>
    </div>
    <!-- END 数据表格 -->
</div>


<div id="layer_supplier_window" style="display: none;overflow-x: hidden;">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">


            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2">选择文件:</label>
                <div class="col-sm-6">
                    <a class="club-import-btn ">
                        <input type="file" id="importSession" name="importSession">
                    </a>
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2">期间:</label>
                   <div class="col-sm-6" style="max-width: 300px;max-height: 300px;">
                       <input type="text" id="period"  name="period"   class="form-control">
                   </div>


            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2">项目主体国家:</label>
                <div class="col-sm-2" style="max-width: 200px;max-height: 300px;">
                    <select id="shopName" name="shopName" class="form-control">
                        <option value="">全部</option>
                        <%for(var dict in shop){%>
                        <option value="${dict.detailName}">${dict.detailName}</option>
                        <%}%>
                    </select>
                </div>
                <div class="col-sm-2" style="max-width: 200px;max-height: 300px;margin-left: -30px">
                    <select id="brandName" name="brandName" class="form-control">
                        <option value="">全部</option>
                        <%for(var dict in brand){%>
                        <option value="${dict.detailName}">${dict.detailName}</option>
                        <%}%>
                    </select>
                </div>
                <div class="col-sm-2" style="max-width: 200px;max-height: 300px;margin-left: -30px">
                    <select id="countryName" name="countryName" class="form-control">
                        <option value="">全部</option>
                        <%for(var dict in country){%>
                        <option value="${dict.detailName}">${dict.detailName}</option>
                        <%}%>
                    </select>
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2"></label>
                <div class="col-sm-6" style="max-width: 300px;max-height: 300px;">
                    <button type="button" class="save-btn btn btn-primary">
                        <i class="fa fa-save"></i> 保存
                    </button>
                </div>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>



<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,chosen,chosen-demo,layui,upload'}){}%>
<script>
    var ind=null;

    laydate.render({
        elem: '#period',
        type: 'month'
        ,trigger: 'click'
    });

    $('.save-btn').on('click',function(){
        layer.closeAll();

        layer.load(2, { //icon支持传入0-2
            shade: [0.1, '#fff'], //0.5透明度的灰色背景
            content: '正在上传数据,请稍后...',
            success: function (layero) {
                layero.find('.layui-layer-content').css({
                    'padding-top': '39px',
                    'margin-left': '-50px',
                    'width': '300px',
                    'font-color': 'red',
                    'font-size': '20px'
                });
            }
        });
        importExcel();
    });

    function importExcel() {
        $.ajax({
            url: "/sea/finance/vt/importDetail/",
            data:  new FormData($('#info-form')[0]),
            type: "post",
            // async: false,
            processData: false,//用于对data参数进行序列化处理 这里必须false
            contentType: false, //必须

            success: function (data) {
                if(data.ok){
                    layer.closeAll();
                    layer.msg("上传成功！",{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    $portTable.bootstrapTable('refresh');
                }else{
                    layer.closeAll(); //关闭弹窗
                    layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){
                            layer.closeAll();
                        }});
                }
            },
            error:function (data) {
                layer.msg("接口异常!请联系管理员!",{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){
                        layer.closeAll();
                    }});
            }
        });
    }

    $('.import-v2-btn').on('click',function () {
        layer.open({
            type:1,
            title:'导入V2数据',
            area:['750px','400px'],
            skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
            shadeClose:false,
            resize: false,
            scrollbar: false,
            maxmin: false,//出现最大化按钮
            content:$('#layer_supplier_window')
        })
    });

    $('.deal-v2-btn').on('click',function () {
        var selDatas = $portTable.bootstrapTable('getSelections');
        if( selDatas.length == 0 ){
            layer.msg('请选择要生成的数据',{icon: 0,shade: [0.8, '#393D49'],time: 1500});
        }else{
            var ids = [];
            $.each(selDatas,function(i,d){
                ids.push(d.id);
            });
            ids = ids.join(',');

            var index= layer.load(2, { //icon支持传入0-2
                shade: [0.1, '#fff'], //0.5透明度的灰色背景
                content: '正在处理数据,请稍后...',
                success: function (layero) {
                    layero.find('.layui-layer-content').css({
                        'padding-top': '39px',
                        'margin-left': '-50px',
                        'width': '300px',
                        'font-color': 'red',
                        'font-size': '20px'
                    });
                }
            });

            $.ajax({
                url: "/sea/finance/vtFile/dealFileStatus/",
                data:  {
                    dealIds:ids
                },
                type: "post",
                success: function (data) {
                    if(data.ok){
                        layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){
                                layer.closeAll();
                            }});
                        $portTable.bootstrapTable('refresh');


                        $.ajax({
                            url: "/sea/finance/vtFile/dealImportSku/",
                            type: "post",
                            success: function (data) {
                                $portTable.bootstrapTable('refresh');
                            }
                        });

                    }else{
                        layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){
                                layer.closeAll();
                            }});
                    }
                },
                error:function (data) {
                    layer.msg("接口异常!请联系管理员!",{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){
                            layer.closeAll();
                        }});
                }
            });
        }
    });

    var $portTable = $('#portTable');
    $(function(){
        //START 表格配置
        $portTable.bootstrapTable({
            columns: [
                {
                    field: 'state',
                    checkbox: true,
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '账期',
                    field: 'period',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '主体',
                    field: 'shopName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '店铺',
                    field: 'brandName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '国家',
                    field: 'countryName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '文件',
                    field: 'fileName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '路径',
                    field: 'fileUrl',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(null!=v && v!=''){
                            var result='<button  class="download-btn layui-btn  layui-btn-sm"  style="margin-top: -6px;margin-left: -4px">';
                            result+='<i class="fa fa-download" aria-hidden="true"></i> <a href="'+v+'" download style="color: white">下载附件</a>';
                            result+='</button>';
                            return result;
                        }else{
                            return '';
                        }
                    }
                },
                {
                    title: '状态',
                    field: 'flag',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v, r) {
                        switch (v) {
                            case 0:
                                return '<label class="control-label has-no"><i class="fa fa-circle" aria-hidden="true"></i> 未处理</label>';
                                break;
                            case 1:
                                return '<label class="control-label has-success"><i class="fa fa-circle" aria-hidden="true"></i> 处理数据中</label>';
                                break;
                            case 2:
                                return '<label class="control- label has-error"><i class="fa fa-circle" aria-hidden="true"></i> 处理失败,请联系管理员</label>';
                                break;
                            case 3:
                                return '<label class="control-label has-success"><i class="fa fa-circle" aria-hidden="true"></i> 处理成功</label>';
                                break;
                        }
                    }
                },
                {
                    title: '创建时间',
                    field: 'createTime',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '开始时间',
                    field: 'startTime',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '结束时间',
                    field: 'endTime',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '数量',
                    field: 'number',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    field: 'operate',
                    title: '操作',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                //删除数据字典详情信息
                $('.del-btn').on('click',function(){
                    var delid = $(this).attr('data-val');
                    //删除提示
                    layer.confirm('确定要删除当前V2数据？<br>', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        layer.closeAll();
                        layer.load();
                        $.post('/sea/finance/vtFile/delete.do',{id: delid},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $portTable.bootstrapTable('refresh');
                                });

                                layer.closeAll();
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                                layer.closeAll();
                            }
                        });
                    });
                });
            }
        });
        //操作菜单
    });

    function optFormatter(value,row){
        var content= '';
        content+='<button class="del-btn btn btn-xs btn-danger" data-val="' + row.id + '" title="删除" style="margin-left: 5px;"><i class="fa fa-trash"></i>删除V2数据</button>';
        return content;
    }

    $('.search-btn').on('click',function(){
        $portTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/finance/vtFile/findByCnd.do?'+$('#search-form').serialize() });
    });

    $('.reload-btn').on('click',function(){
        layer.confirm('确定要情况当前V2数据？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){

            layer.closeAll();
            layer.load();
            $.post('/sea/finance/vt/reload.do',{},function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                        //刷新页面
                        layer.closeAll();
                        $portTable.bootstrapTable('refresh');
                    });
                }else{
                    layer.msg(data.msg,{icon: 0,time: 5000},function () {
                        layer.closeAll();
                    });
                }
            });
        });
    });

</script>
</body>
</html>
